var myLayout;
$(function () {
    myLayout = $('body').layout({
        north__minSize: 50,
        north__maxSize: 400,
        togglerContent_open: '<div class="ui-icon"></div>',
        togglerContent_closed: '<div class="ui-icon"></div>'
        // , spacing_open: 10
        // , spacing_closed: 10
    });

// 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header: '用户ID', frozen: true, name: 'userId', index: "a.user_id", width: 45, align: 'center', key: true},
            {header: '用户名', name: 'username',index: "a.username", width: 75},
            {header: '邮箱', name: 'email',index: "a.email", width: 90},
            {header: '手机号', name: 'mobile',index: "a.mobile", width: 100},
            {
                header: '状态', name: 'status',index: "a.status", width: 60, formatter: function (value, options, row) {
                    return value === 0 ?
                        '<span class="label label-danger">禁用</span>' :
                        '<span class="label label-success">正常</span>';
                }
            },
            {header: '创建时间', name: 'createTime', index: "a.createTime", width: 85},
            {
                header: '操作',
                name: 'actions',
                width: 270,
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var actions = [];
                    actions.push('<a href="/js/a/sys/empUser/form?userCode=' + row.userCode + '&op=edit" class="btnList" title="编辑用户"><i class="fa fa-pencil"></i></a>&nbsp;');
                    if (row.status == Global.STATUS_NORMAL) {
                        actions.push('<a href="/js/a/sys/empUser/disable?userCode=' + row.userCode + '" class="btnList" title="停用用户" data-confirm="确认要停用该用户吗？"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
                    } else if (row.status == Global.STATUS_DISABLE || row.status == Global.STATUS_FREEZE) {
                        actions.push('<a href="/js/a/sys/empUser/enable?userCode=' + row.userCode + '" class="btnList" title="启用用户" data-confirm="确认要启用该用户吗？"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
                    }
                    actions.push('<a href="/js/a/sys/empUser/delete?userCode=' + row.userCode + '" class="btnList" title="删除用户" data-confirm="确认要删除该用户吗？"><i class="fa fa-trash-o"></i></a>&nbsp;');
                    actions.push('<a href="javascript:" class="btnMore" title="更多操作"><i class="fa fa-chevron-circle-right"></i></a>&nbsp;');
                    actions.push('<div class="moreItems">');
                    actions.push('<a href="/js/a/sys/empUser/form?userCode=' + row.userCode + '&op=auth" class="btn btn-default btn-xs btnList" title="用户分配角色"><i class="fa fa-check-square-o"></i> 分配角色</a>&nbsp;');
                    actions.push('<a href="/js/a/sys/empUser/formAuthDataScope?userCode=' + row.userCode + '" class="btn btn-default btn-xs btnList" title="用户分配数据权限"><i class="fa fa-check-circle-o"></i> 数据权限</a>&nbsp;');
                    actions.push('<a href="/js/a/sys/empUser/resetpwd?userCode=' + row.userCode + '" class="btn btn-default btn-xs btnList" title="用户密码重置" data-confirm="确认要将该用户密码重置到初始状态吗？"><i class="fa fa-reply-all"></i> 重置密码</a>&nbsp;');
                    actions.push('</div>');
                    return actions.join('');
                }
            }
        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });
});

function reload() {
    var page =   $('#dataGrid').dataGrid('getGridParam', 'page');
    $('#dataGrid').dataGrid('setGridParam', {
        postData: {'username': vm.q.username},
        page: page
    }).trigger("reloadGrid");
}